package com.itcam.insertsort;

import java.util.Arrays;
import java.util.List;

import static java.util.Collections.sort;

/**
 * @author : Cammy.Wu
 * Description : 
 */

public class InsertSort {
    public static void main(String[] args) {
        int[] a = {9, 5, 7, 12, 1, 3};
        List<Integer> list = Arrays.asList(9, 5, 7, 12, 1, 3);
        System.out.println(Arrays.toString(a));
        insertSort(a, a.length - 1);
        System.out.println(Arrays.toString(a));
    }

    private static void insertSort(int[] arr, int n) {
        for (int low = 1; low <= n; low++) {
            int temp = arr[low];
            int i = low - 1;
            while (i >= 0 && arr[i] > temp) {
                arr[i + 1] = arr[i];
                i--;
            }
            if (i != low - 1) {
                arr[i + 1] = temp;
            }
        }
    }
}
